<%@ page 
	language="java" 
	contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" 
    import="java.util.*,java.sql.*,java.text.*,java.lang.*,java.io.*"
%>
<%@page import="ca.concordia.soen6461.wichf.navigation.view.HomeViewBean"%>

<%
  /* The following code will be removed once the servlet is used. */
  // HomeView view = new HomeView(null);
  // request.setAttribute("view", view.render(null));
%>

<%
	HomeViewBean bean = (HomeViewBean) request.getAttribute("view");
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>HOME PAGE</title>
  </head>
  <body>
    <jsp:include page="/header.jsp"></jsp:include>
    <% if (bean.isViewCartLink()) { %> 
    <a href="?event=ViewCartEvent">View Cart</a>
    <% } %>      
    <form name="home" action="" method="post">
      <jsp:include page="/messages.jsp"></jsp:include>
      <h2><font color="green">Select Appointment :</font></h2>
      <table align=center cellpadding=5 cellspacing=0 bgcolor="#D5FFD5">
        <tr align="center">
          <td></td>
          <% 
            for (HomeViewBean.Day day : bean.getDays()) {
          %>
          <td><font size="5"><%=day.getName()%></font></td>
          <% 
            }
          %>
        </tr>
        <%
          int t = 0;
          for (String time : bean.getTimes()) {
        %>
        <tr>
          <td><%=time%></td>
        <%
            int d = 0;
            for (HomeViewBean.Day day : bean.getDays()) {
            	HomeViewBean.TimeSlot slot = day.getTimeSlots().get(t);
              String color = "white";
              if (slot.isAppointment()) {
                color = "cyan"; 
              } else if (slot.getActions().isEmpty()) {
                color = "grey"; 
              }
        %>
          <td style="background-color: <%=color%>">
            <%
              for (String action : slot.getActions().keySet()) {
                String actionLabel = slot.getActions().get(action);
            %>
            <div><a href="?event=<%=action%>&day=<%=d%>&time=<%=t%>" style="font-size: xx-small"><%=actionLabel%></a></div>
            <% 
              }
            %>
          </td>
        <%
              d++;
            }
        %>
        </tr>
        <%
            t++;
          }
        %>
  </table>
</form>
</body>
</html>